<%--
 *  File:   FormalInvDataDetailView.jsp
 *  Desc:	
 *
 *  Date		         Author		      Changes
 *  2010-07-0-12	     kenfang		  Created
 *
 *  Copyright (C) 2000 - 2005 Oval Technologies, Inc.
 *  All rights reserved.
 *
 *  This software is the confidential and proprietary information of Oval
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>
<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java" %>     
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>

<%@ page contentType = "text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>
<%
    //init param
    String privilegeCode = "E0322";
    String strModuleName = "COM";
    String contextPath = request.getContextPath();
    
    String dateFormat = (String)session.getAttribute("dateformat");
  	if(dateFormat==null)
  		dateFormat = "yyyy-MM-dd";
  	String languagecode = (String)session.getAttribute("languagecode");
  	if(languagecode==null)
  		languagecode = "cn";
%>
<% //--------------------------------------  include files list --%>
<%@ include file="/inc/Security.inc" %>
<%@ include file="/inc/FrmDefault.inc" %>
<%@ include file="/inc/PageDefault.inc" %>
<%@ include file="/inc/LocationDefault.inc" %>
<html>
<head>
<title>FormalSalesDataDetailView</title>
<PageFlow:CheckPageFlow pageName="p_formalinventorydatadetailview"/>
<link rel="stylesheet" href="<%=contextPath %>/css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="<%=contextPath %>/css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="<%=contextPath %>/js/ScriptLib.js"></script>
<script language="JavaScript" src="<%=contextPath %>/js/Calendar.js"></script>
<%@ include file="/inc/SummaryDivision.inc" %>
<%@ include file ="/inc/NewCalendar.inc" %>
<%
request.setAttribute("random", OvalTools.randomURL());
request.setAttribute("dateFormat","yyyy-MM-dd");
Vector totalsummary = (Vector)pageContext.getAttribute("totalsummary");
if( totalsummary == null ){
	totalsummary = new Vector();
}
if( totalsummary.size() == 0 ){
	pageContext.setAttribute("isEmpty","Y");
}else{
	pageContext.setAttribute("isEmpty","N");
}
pageContext.setAttribute("fromto","--");
%>
<script>
	function page_summary(actionvalue,orderbyname)
	{
		  if(isEmpty(document.cform.startdate.value) || isEmpty(document.cform.enddate.value)){
			  
			  alert("<%= message.getMessageDesc("TimePeriod_NOT_NULL",label.getLabelName("L_TimePeriod"))%>");
			    return;
			  }		
		if(!checkDate()) return;
	  var editform = summaryPrepare(cform,actionvalue,orderbyname);
	  editform.action = "FormalInvDataDetailView.jsp?<%= OvalTools.randomURL() %>";
	  editform.target = "_self";
	  isRunning = true;
	  editform.submit();  
	}
	function checkDate(){
		if(!isEmpty(document.cform.startdate.value) && !isEmpty(document.cform.enddate.value))
		  {
		    var startdate=dateCheck(document.cform.startdate.value, 'yyyy-MM-dd', '<%=JspHelper.filterNull( dateFormat )%>');
		    var enddate=dateCheck(document.cform.enddate.value, 'yyyy-MM-dd', '<%=JspHelper.filterNull( dateFormat )%>');
		    if(enddate<startdate)
		    {
		      alert('<%=message.getMessageDesc("CAN_NOT_LATE_THAN",label.getLabelName("L_BeginningDate",false),label.getLabelName("L_EndingDate",false))%>');
		      return false;
		    }
		    
		    
		  }
		  return true;
	}
	function page_setRegion(code,name)
	{
	  if(code != document.cform.regioncode.value)
	  {
	    document.cform.citycode.value = "";
	    document.cform.cityname.value = "";
	  }
	  document.cform.regioncode.value = code;
	  document.cform.regionname.value = name;
	  if (popwindow != null)
	    popwindow.close();
	}
	
	function page_selectProvince()
	{
	  if(popwindow!=null)
	    popwindow.close();
	  popwindow = window.open('<%=contextPath %>/masterdata/ogm/RegionSelect.jsp?<%= OvalTools.randomURL() %>&languagecode=<%= strLanguageCode %>&countrycode=CN','newwindow', 'height=250, width=500,top=100,left=100,toolbar=n0, menubar=no, scrollbars=no, resizable=no, location=no, status=no');
	}
	function page_selectCity()
	{
	  var regioncode = document.cform.regioncode.value;
	  if(regioncode=="" || regioncode==-1)
	  {
	    alert("<%= message.getMessageDesc("MUST_SELECT_FIRST",label.getLabelName("L_Province"))%>");
	    return;
	  }
	  if(popwindow!=null)
	    popwindow.close();
	  popwindow = window.open('<%=contextPath %>/masterdata/ogm/CitySelect.jsp?<%= OvalTools.randomURL() %>&languagecode=<%= strLanguageCode %>&countrycode=CN&regioncode=' + regioncode,'newwindow', 'height=250, width=400,top=100,left=100,toolbar=n0, menubar=no, scrollbars=yes, resizable=no, location=no, status=no');
	}
	
	function page_setCity(code,name)
	{
	  document.cform.citycode.value = code;
	  document.cform.cityname.value = name;
	  if (popwindow != null)
	    popwindow.close();
	}
	function page_cleancode(type){
		var  datahandler = new  DataHandler();
		
		if(type == 'region'){
			if(cform.regioncode.value == ''){
				cform.regioncode.value = '';
				cform.regionname.value = '';
				cform.citycode.value = '';
				cform.cityname.value = '';	
			}else{
				datahandler.add_params("regioncode" , cform.regioncode.value);
				datahandler.getResult("regioncode","cform.regioncode"); 
				datahandler.getResult("regionname","cform.regionname"); 
				datahandler.add_job("j_getregionbycode");
			}
		} 
	
		if(type == 'city'){
			if(cform.regionname.value == "" || cform.regionname.value == -1){
				alert("<%= message.getMessageDesc("MUST_SELECT_FIRST",label.getLabelName("L_Province"))%>");
				cform.citycode.value = '';
				cform.cityname.value = '';		  
				return;
			}
			
			if(cform.citycode.value == ''){
				cform.citycode.value = '';
				cform.cityname.value = '';
			}else{
				datahandler.add_params("regioncode" , cform.regioncode.value);
				datahandler.add_params("citycode" , cform.citycode.value);
				datahandler.getResult("citycode","cform.citycode"); 
				datahandler.getResult("cityname","cform.cityname"); 
				datahandler.add_job("j_getcitybycode");
			}			
		}else if(type == 'customer'){
			if(cform.customercode.value == ''){
				cform.customercode.value = '';
				cform.customername.value = '';
				cform.customerid.value = '';
			}else {
				datahandler.add_params("orgcode" , cform.customercode.value);
				datahandler.getResult("orgcode","cform.customercode"); 
				datahandler.getResult("orgname","cform.customername"); 
				datahandler.getResult("orgid","cform.customerid"); 
				datahandler.add_job("j_getorgbycode");
			}
		}else if(type == 'parterner'){
			if(cform.dealercode.value == ''){
				cform.dealercode.value = '';
				cform.dealername.value = '';
				cform.dealerid.value = '';
			}else {
				datahandler.add_params("orgcode" , cform.dealercode.value);
				datahandler.getResult("orgcode","cform.dealercode"); 
				datahandler.getResult("orgname","cform.dealername"); 
				datahandler.getResult("orgid","cform.dealerid"); 
				datahandler.add_job("j_getorgbycode");
				
			}
		}else if(type == 'product'){
			if(cform.prodcode.value == ''){
				cform.prodcode.value = '';
				cform.prodname.value = '';
				cform.prodid.value = '';
			}else{
				datahandler.add_params("prodcode" , cform.prodcode.value);
				datahandler.add_params("languagecode" , '<%=languagecode%>');
				datahandler.getResult("prodcode","cform.prodcode"); 
				datahandler.getResult("prdn","cform.prodname"); 
				datahandler.getResult("prodid","cform.prodid"); 
				datahandler.add_job("j_getproductbycode");
			}			
		}
	
		datahandler.runDataHandler();	
	}
	function page_selectProd() {
		var status = "height=400, width=600,top=100,left=100,toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no";
		var url = "../../masterdata/kdm/ProductSelect.jsp?o_thread=" + Math.random();
			
		if (typeof popwindow != 'undefined') popwindow.close();
		popwindow = window.open(url, "newwindow", status);
	}
	function page_setproduct(id,umcode,prodcode,prodname)
	{
		document.cform.prodid.value=id;
		document.cform.prodcode.value=prodcode;
		document.cform.prodname.value=prodname;
	}
	function popDealer() {
	  opt = "dealer";
	  var regioncode = document.cform.regioncode.value;
	  var citycode = document.cform.citycode.value;
	  var status = "height=450, width=600, top=100, left=100, toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no";
			var url = "<%=contextPath %>/masterdata/ogm/OrgSelect.jsp?o_thread=" + Math.random();
			url += "&orgglobalpccode=100";
			url +="&regioncode=" + regioncode+"&citycode="+citycode;
			
			if (typeof popwindow != 'undefined') popwindow.close();
			popwindow = window.open(url, "newwindow", status);
	}
	
	function popCustomer() {
	  opt = "customer";
	
	  var status = "height=450, width=600, top=100, left=100, toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no";
			var url = "<%=contextPath %>/masterdata/ogm/OrgSelect.jsp?o_thread=" + Math.random();
			url += "&orgglobalpccodes=111,999";
			
			if (typeof popwindow != 'undefined') popwindow.close();
			popwindow = window.open(url, "newwindow", status);
	}
	function page_setOrg(id, name, code,shortname) {
	  if(opt == "dealer"){
	  	cform.dealerid.value=id;
	  	cform.dealercode.value = code;
	  	cform.dealername.value = name;
	  }
	  if(opt == "customer"){
	  	cform.customerid.value=id;
	  	cform.customercode.value = code;
	  	cform.customername.value = name;
	  }	
	  opt = "";
	  if (popwindow != null)
	    popwindow.close();
	}
</script>
</head>
<body>
<iframe id="reloadHandler" name="reloadHandler" style="display:none"></iframe>
<% //--------------------------------------  page location --%>
<%@ include file="/inc/PageLocation.inc" %>
<table width="100%" cellspacing="0" border="0" cellpadding="0">
<form name="cform" action="<%=contextPath%>/Dispatcher"  method="post">
<input type="hidden" name="pagename" value="p_formalinventorydatadetailview">
<input type="hidden" name="actionname">
<custom:hidden property="isfirst" value="N" />
<custom:hidden property="datafrequency"/>

<tr>
	<td>
		<table width="100%" border="0" cellspacing="0" onkeydown="if(event.keyCode==13) page_summary('search');">  
			<tr>
	          	<td class="td_right"><%= label.getLabelName("L_Province") + label.getLabelName("L_Colon") %></td>
	            <td>
	            	<custom:text property="regioncode" label="L_Province" size="10" onchange="page_cleancode('region')" />
	            	<a onclick="javascript:page_selectProvince();"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a>
	            	<custom:text property="regionname" readonly="true" size="20"/>
	            </td>
	         	<td class="td_right"><%= label.getLabelName("L_City") + label.getLabelName("L_Colon") %></td>
	          	<td>
	          		<custom:text property="citycode" size="10" onchange="page_cleancode('city')" />
	            	<a onclick="javascript:page_selectCity();"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a>
	            	<custom:text property="cityname" readonly="true" size="20"/>
	            </td>
	         </tr>
	         <tr>
	          	<td class="td_right"><%= label.getLabelName("L_Product") + label.getLabelName("L_Colon") %></td>
	            <td>
	            	<custom:text property="prodcode"  size="10" onchange="page_cleancode('product')"/>
	            	<a onclick="javascript:page_selectProd();"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a>
	            	<custom:text property="prodname" readonly="true" size="20"/>
	            	<custom:hidden property="prodid" />
	            </td>
	         	<td class="td_right">&nbsp;</td>
	          	<td>&nbsp; </td>
	         </tr>
	         <tr>
	          	<td class="td_right"><%= label.getLabelName("L_Partner") + label.getLabelName("L_Colon") %></td>
	            <td>
	            	<custom:text property="dealercode" command="notnull" label="L_Province" size="10" onchange="page_cleancode('parterner')"/>
	            	<a onclick="javascript:popDealer();"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a>
	            	<custom:text property="dealername" readonly="true" size="20"/>
	            	<custom:hidden property="dealerid" />
	            </td>
	         	<td class="td_right"><%= label.getLabelName("L_Status") + label.getLabelName("L_Colon") %></td>
	          	<td>
	          		<%
         			Integer statusO = (Integer)pageContext.getAttribute("status");
         			if(statusO == null) statusO = new Integer(0);
         			int status = statusO.intValue();
         			String startdate = (String)pageContext.getAttribute("startdate");
         			if(startdate == null) startdate = "";
         			String enddate = (String)pageContext.getAttribute("enddate");
         			if(enddate == null) enddate = "";
         		%>
         		<custom:selectdic dictType="Status" property="status" defaultValue="---------" defaultValueCost="" valueCriteria="80"/>
	            </td>
	         </tr>
	         <tr>
	          	<td class="td_right"><%= label.getLabelName("L_filename") + label.getLabelName("L_Colon") %></td>
	            <td>
	            	<custom:text property="filename" size="20"/>
	            </td>
	         	<td class="need"><%= label.getLabelName("L_TimePeriod") + label.getLabelName("L_Colon") %></td>
	          	<td>
	          		<input type="text" name="startdate" value="<%=JspHelper.filterNull( startdate )%>" onblur="if(startdate.value<0){alert('<%= message.getMessageDesc("VALUE_MUST_BE_DATE",label.getLabelName("L_BeginningDate",false)) %>');startdate.focus();}">
	          		<a onclick="javascript:c.show(this,'cform.startdate','<%=JspHelper.filterNull( session.getAttribute("dateformat") )%>')">
	          			<custom:button type="3" label="L_Asterisk" imgsrc="Time.gif" border="0"/></a> --
	          		<input type="text" name="enddate" value="<%=JspHelper.filterNull( enddate )%>" onblur="if(enddate.value<0){alert('<%= message.getMessageDesc("VALUE_MUST_BE_DATE",label.getLabelName("L_EndingDate",false)) %>');enddate.focus();}">
	          		<a onclick="javascript:c.show(this,'cform.enddate','<%=JspHelper.filterNull( session.getAttribute("dateformat") )%>')">
	          			<custom:button type="3" label="L_Asterisk" imgsrc="Time.gif" border="0"/></a> 
	          		<a href="javascript:page_summary('search')"><img src="<%= contextPath %>/images/<%= strLanguageCode %>/go_fy.gif" border="0" style="border: 1 solid #000000"></a>
	          	</td>
	         </tr>
		</table>
	</td>
</tr>
<tr>
	<td>
		<table width="100%" border="1" cellpadding="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellspacing="0" align="center">
         <tr  class="deepblue-left"> 
            <td width="*" class="title_center"><%= label.getLabelName("L_filename")%></td>
            <td width="20%" class="title_center"><%= label.getLabelName("L_Partner") %></td>
            <td width="5%" class="title_center"><%= label.getLabelName("L_ProdCode") %></td>
            <td width="10%" class="title_center"><%= label.getLabelName("L_ProdName") %></td>
            <td width="5%" class="title_center"><%= label.getLabelName("L_Qty") %></td>
            <td width="5%" class="title_center"><%= label.getLabelName("L_Spec") %></td>
            <td width="9%" class="title_center"><%= label.getLabelName("L_InvDate") %></td>
            <td width="5%" class="title_center"><%= label.getLabelName("L_FileStatus") %></td>
         </tr>
         <%
             int j = 0;
             String strClassType = new String(); 
            // Vector totalsummary = (Vector)pageContext.getAttribute("totalsummary");
            // if(totalsummary == null) totalsummary = new Vector();
          %>
          <logic:iterate id="summary" collection="<%= totalsummary %>">                      
         <%
            HashMap summaryMap = (HashMap)pageContext.getAttribute("summary");
            if(summaryMap == null) summaryMap = new HashMap();
            
            if(j%2 == 1){
              strClassType = "td-listrom";             
            }else{                    
              strClassType = "";
            }
              
            j++;     
          %>
           <tr onmouseover="this.className='tr-over'" onmouseout="this.className='<%=JspHelper.filterNull(strClassType)%>'" class="<%=JspHelper.filterNull(strClassType)%>">
            <td>&nbsp;<custom:write property="filename" name="summary"/></td>
            <td>&nbsp;<custom:write property="orgname" name="summary"/></td>
            <td>&nbsp;<custom:write property="prodcode" name="summary" nbsp="true"/></td>
            <td>&nbsp;<custom:write property="prdn" name="summary" nbsp="true"/></td>
            <td>&nbsp;<custom:write property="qtyall" name="summary" nbsp="true"/></td>
            <td>&nbsp;<custom:write property="itemspec" name="summary" nbsp="true"/></td>
            <td>&nbsp;<custom:write property="startdate" name="summary" nbsp="true" dataType="date" dataFormat="yyyy-MM-dd"/></td>
            <td>&nbsp;<custom:write property="filestatus" name="summary" nbsp="true" dictType="Status"/></td>
          </tr>
          </logic:iterate>
      <% //--------------------------------------  flipping page --%>
      <%@ include file="/inc/SummaryAction.inc" %>
        </table>
	</td>
</tr>
</table>
</form>
</body>
</html>